package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.dto.SetmealDTO;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.mapper.MemberMapper;
import com.itheima.health.mapper.SetmealMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Member;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.MemberService;
import com.itheima.health.service.SetmealService;
import com.itheima.health.utils.resources.RedisConstant;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.PoiVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {


    @Override
    public Member findMemeberByTelephone(String telephone) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("PHONENUMBER",telephone);
        return baseMapper.selectOne(queryWrapper);
    }
    @Override
    public HashMap<String, ArrayList> findmember() {
        ArrayList<PoiVO> list = baseMapper.findmember();
        HashMap<String, ArrayList> map = new HashMap<>();
        ArrayList<String> yearAndMonth = new ArrayList<>();
        ArrayList<Integer> memberCounts = new ArrayList<>();
        for (PoiVO poiVO : list) {
            String andMonth = poiVO.getYearAndMonth();
            yearAndMonth.add(andMonth);
            Integer counts = poiVO.getMemberCounts();
            memberCounts.add(counts);
        }
        map.put("yearAndMonth",yearAndMonth);
        map.put("memberCounts", memberCounts);
        return map;
    }

    @Override
    public HashMap<String, ArrayList> findMemberByDate(String begin, String end) {
        ArrayList<PoiVO> list = baseMapper.findMemberByDate(begin,end);
        HashMap<String, ArrayList> map = new HashMap<>();
        ArrayList<String> yearAndMonth = new ArrayList<>();
        ArrayList<Integer> memberCounts = new ArrayList<>();
        for (PoiVO poiVO : list) {
            String andMonth = poiVO.getYearAndMonth();
            yearAndMonth.add(andMonth);
            Integer counts = poiVO.getMemberCounts();
            memberCounts.add(counts);
        }
        map.put("yearAndMonth",yearAndMonth);
        map.put("memberCounts", memberCounts);
        return map;
    }

    @Override
    public List<HashMap> findmemberBySex() {
        return baseMapper.findmemberBySex();

    }
    @Override
    public List<HashMap>findmemberByAge() {

        return baseMapper.findmemberByAge();

    }
}



